package com.example.designsoft;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.graphics.Color;
import android.graphics.Point;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

import com.example.designsoft.build.ComputerDesign;
import com.example.designsoft.freesizedraggablelayout.DetailView;
import com.example.designsoft.freesizedraggablelayout.FreeSizeDraggableLayout;
import com.example.designsoft.mvpexercise.MvpExerciseActivity;
import com.example.designsoft.mvptest.MvpTestActivity;
import com.example.designsoft.util.GlideUtils;
import com.example.designsoft.view.CustomSwitchButton;
import com.example.designsoft.view.PullPageView;


import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private CustomSwitchButton mCustomButton;
    private Button bt;
    private FreeSizeDraggableLayout fsdLayout;
    final int DEMONUM = 4;
    int iDemoID = 5;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        fsdLayout = findViewById(R.id.fsd_layout);
//        setData(fsdLayout, iDemoID);
        mCustomButton = findViewById(R.id.csb);
        mCustomButton.setOnTurnStatusClickListener(new CustomSwitchButton.onTurnStatusClickListener() {
            @Override
            public void onTurnOnClick() {
                mCustomButton.startOnAnimal();
            }

            @Override
            public void onTurnOffClick() {
                mCustomButton.startOffAnimal();
            }
        });
        bt = findViewById(R.id.bt);
        bt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(MainActivity.this, MvpExerciseActivity.class));
            }
        });
    }
    private void setData(FreeSizeDraggableLayout freeSizeDraggableLayout, int id) {
        List<DetailView> list = new ArrayList<>();
        if (id % DEMONUM == 0) {
            list.add(new DetailView(new Point(0, 0), 2, 2, createButton(1)));
            list.add(new DetailView(new Point(2, 0), 2, 2, createButton(2)));
            list.add(new DetailView(new Point(0, 2), 2, 2, createButton(3)));
            list.add(new DetailView(new Point(2, 2), 2, 2, createButton(4)));
        }
        if (id % DEMONUM == 1) {
//            list.add(new DetailView(new Point(0, 0), 4, 2, createButton(1)));
//            list.add(new DetailView(new Point(4, 0), 2, 1, createButton(2)));
//            list.add(new DetailView(new Point(4, 1), 2, 1, createButton(3)));
//            list.add(new DetailView(new Point(0, 2), 2, 1, createButton(4)));
//            list.add(new DetailView(new Point(2, 2), 2, 1, createButton(5)));
//            list.add(new DetailView(new Point(4, 2), 2, 1, createImage(6,"")));

            list.add(new DetailView(new Point(4, 2), 2, 1, createImage(1,"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1608621548&di=3d2b8b26a7433e575bce506557b0af15&imgtype=jpg&er=1&src=http%3A%2F%2Fi1.sinaimg.cn%2FIT%2F2010%2F0419%2F201041993511.jpg")));
            list.add(new DetailView(new Point(4, 0), 2, 1, createImage(2,"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1608621507&di=a40a4ef4e4ef5a038a89b3c568a19a4d&imgtype=jpg&er=1&src=http%3A%2F%2Fa4.att.hudong.com%2F27%2F67%2F01300000921826141299672233506.jpg")));
            list.add(new DetailView(new Point(4, 1), 2, 1, createImage(3,"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1608621584&di=46ea19109681655269adba5ce4519422&imgtype=jpg&er=1&src=http%3A%2F%2Fa4.att.hudong.com%2F25%2F99%2F19300000421423134190997943822.jpg")));
            list.add(new DetailView(new Point(0, 2), 2, 1, createImage(4,"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1608621629&di=880af305285d17d4d006390f459b912a&imgtype=jpg&er=1&src=http%3A%2F%2Fimg.alicdn.com%2Fimgextra%2Fi4%2F1652727765%2FTB23KiLXp5N.eBjSZFKXXX_QVXa_%21%211652727765.jpg")));
            list.add(new DetailView(new Point(2, 2), 2, 1, createImage(5,"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1608621648&di=c98d56941e74b3129c03244b597af9d8&imgtype=jpg&er=1&src=http%3A%2F%2Fpic.baike.soso.com%2Fp%2F20140408%2F20140408130734-1854992764.jpg")));
            list.add(new DetailView(new Point(0, 0), 4, 2, createImage(6,"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1608621670&di=5356cc932af09361160f3877e6d8b0de&imgtype=jpg&er=1&src=http%3A%2F%2Fimg.mp.itc.cn%2Fupload%2F20160401%2F0afbd3bc77cb4788b4e5cab5e7e4b97f_th.jpg")));

        }
        if (id % DEMONUM == 2) {
            list.add(new DetailView(new Point(0, 0), 2, 1, createButton(1)));
            list.add(new DetailView(new Point(0, 1), 2, 1, createButton(2)));
            list.add(new DetailView(new Point(2, 0), 2, 2, createButton(3)));
            list.add(new DetailView(new Point(0, 2), 1, 2, createButton(4)));
            list.add(new DetailView(new Point(1, 2), 1, 2, createButton(5)));
            list.add(new DetailView(new Point(2, 2), 1, 2, createButton(6)));
            list.add(new DetailView(new Point(3, 2), 1, 1, createButton(7)));
            list.add(new DetailView(new Point(3, 3), 1, 1, createButton(8)));
        }
        if (id % DEMONUM == 3) {
            list.add(new DetailView(new Point(0, 0), 2, 2, createWebView(1)));
            list.add(new DetailView(new Point(2, 0), 2, 1, createWebView(2)));
            list.add(new DetailView(new Point(2, 1), 2, 1, createWebView(3)));
            list.add(new DetailView(new Point(0, 2), 4, 2, createWebView(4)));
        }
        freeSizeDraggableLayout.setList(list);
    }
    private Button createButton(int i) {
        final Button btn = new Button(getApplicationContext());
        btn.setText("Button - " + i);
        btn.setBackgroundColor(Color.BLACK);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(getApplicationContext(), btn.getText(), Toast.LENGTH_SHORT).show();
            }
        });
        return btn;
    }
    private ImageView createImage(int i, String url) {
        final ImageView img = new ImageView(getApplicationContext());
        GlideUtils.glideCenterCrop(MainActivity.this,url,5,img);
        img.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

            }
        });
        return img;
    }

    private WebView createWebView(int i) {
        WebView webView = new WebView(getApplicationContext());
        webView.loadData("<h2>" + i + "</h2><h2>" + i + "</h2><p style=\"color:red\">this is a webview</p><p style=\"color:green\">this is a webview</p><p style=\"color:blue\">this is a webview</p><p>this is a webview</p>", "text/html", "utf-8");
        webView.setBackgroundColor(Color.GRAY);
        return webView;
    }
}
